# coding=utf-8
from django.contrib import admin
from models import *


class ProjectAdmin(admin.ModelAdmin):
    list_display = (u'name', u'create_time')
    search_fields = (u'name',)
    list_filter = (u'name',)
    list_per_page = 20


class ModuleAdmin(admin.ModelAdmin):
    # 引用的是外键，所以要用project_id而不是project_id__name
    list_display = (u'name',u'person_in_charge', u'project_id',  u'completion_rate')
    search_fields = (u'name', u'project_id__name', u'person_in_charge')
    list_filter = (u'project_id__name',)
    readonly_fields = (u'completion_rate',)
    list_per_page = 20


class FunctionAdmin(admin.ModelAdmin):
    list_display = (u'project_id', u'module_id', u'function_point', u'completion')
    search_fields = (u'project_id__name', u'module_id__name', u'function_point', u'completion')
    list_filter = (u'project_id__name', u'module_id__name')
    ordering = ('-project_id', '-module_id',)


class AccessLogAdmin(admin.ModelAdmin):
    list_display = (u'route', u'ip', u'access_time')
    list_per_page = 20
    readonly_fields = (u'route', u'ip', u'access_time')


# Register your models here.
admin.site.register(AccessLog, AccessLogAdmin)
admin.site.register(Project, ProjectAdmin)
admin.site.register(Module, ModuleAdmin)
admin.site.register(Function, FunctionAdmin)
